package com.prosay.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class logoutServlet
 */
public class LogoutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public void service(HttpServletRequest request,HttpServletResponse response) throws IOException{
    	HttpSession session = request.getSession();
    	System.out.println("sessionId :" + session.getId());
    	// 主动让sess 失效
    	session.invalidate();
    	
    	System.out.println("sessionId2 :" + session.getId());
    	// 在实际工作中session 中不可能只存用户的信息，可能还在存储用户对应的权限数据
    	//session.removeAttribute("userName");
    	// 重定向到首页的登录页
    	response.sendRedirect("../index.html");
    }
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
